//
//  SXiangqingViewController.m
//  News
//
//  Created by dlios on 15-5-13.
//  Copyright (c) 2015年 PEAK. All rights reserved.
//

#import "SXiangqingViewController.h"

@interface SXiangqingViewController () <UIWebViewDelegate>

@property(nonatomic, retain) UIWebView *web;
@property(nonatomic ,retain)SNewsxiangQingTwo * xiangQing;
@property(nonatomic ,retain)SNewSxiangQingImgOne * xiangQingImg;

@property(nonatomic ,retain)NSArray * imgArr;
@property(nonatomic, retain) UIActivityIndicatorView *activityIndicator;
@property(nonatomic ,retain)UIImageView *imageView;


@end

@implementation SXiangqingViewController

-(void)dealloc
{
    [_IdStr release];
    [_web release];
    [_xiangQing release];
    [_xiangQingImg release];
    [_imgArr release];
    [_activityIndicator release];
    [_imageView release];
    [super dealloc];
    
    
}
- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBar.translucent = NO;

    self.view.backgroundColor = [UIColor whiteColor];
    self.title  = @"详情";
    

    
    //请求出现小菊花
    self.imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    _imageView.image = [UIImage imageNamed:@"5EA2D64D-15BE-43D8-AB18-E15BCE039C8F"];
 
    _imageView.alpha = 1;
    [self.view addSubview:_imageView];
    [_imageView release];
    
    _activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
    [_activityIndicator setCenter:_imageView.center];
    [_activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
    [_imageView addSubview:_activityIndicator];
    [_activityIndicator startAnimating];
    

    
    [self getData];
  
    
}


-(void)getData
{

    NSString * tempStr = [NSString  stringWithFormat:@"http://c.m.163.com/nc/article/%@/full.html",_IdStr];

    [SNetWorkHandle getDataWithURL:tempStr completion:^(id result) {

        NSDictionary * xiangQingDic = [result objectForKey:_IdStr];

       self.xiangQing  = [[ SNewsxiangQingTwo alloc] initWithDic:xiangQingDic];

        self.imgArr = (NSArray * )_xiangQing.img;
        
        _xiangQing.ImgArr = [NSMutableArray array];
        
        NSString *str1 = [NSString stringWithFormat:@"<h1>%@</h1>", _xiangQing.biaoti];
        _xiangQing.body = [str1 stringByAppendingString:_xiangQing.body];
        for (NSDictionary * tempDic in _imgArr) {
            
            self.xiangQingImg = [[SNewSxiangQingImgOne alloc] initWithDic:tempDic];
            
       NSArray *arr = [_xiangQingImg.pixel componentsSeparatedByString:@"*"];
            
            _xiangQingImg.width = arr[0];
            _xiangQingImg.height = arr[1];

            [_xiangQing.ImgArr addObject:_xiangQingImg];
        
        
        }

        for (SNewSxiangQingImgOne * Two in _xiangQing.ImgArr) {

            
            NSString * str = [NSString stringWithFormat:@"<img width=%lf src=\"%@\">", self.view.bounds.size.width - 20,Two.src];
            

            _xiangQing.body = [_xiangQing.body stringByReplacingOccurrencesOfString:Two.ref withString:str];
            
        }
        

        [self createView];
        
        [self.imageView removeFromSuperview];
        
    }];
    
    
}

/**
 *  创建视图
 */
-(void)createView
{

        self.web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height )];


    [_web loadHTMLString:_xiangQing.body baseURL:nil];
    
    [self.view addSubview:_web];
    _web.scrollView.bounces = NO;
    _web.delegate = self;

    [_web release];
    
   
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
